Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image Tracking Doubles Request in Chrome #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Image Tracking Doubles Request in Chrome #3

wants to merge 1 commit into from

Conversation

EricByers
Copy link

In Chrome (and potentially others) setting the img.src before appending it to the Dom triggers the img to be loaded. It also can be loaded again when it is attached to the DOM, causing a double track.

Moving the setting of the src till after it is appended alleviates this issue.

… to prevent double trackign in some browser
@malectro
Copy link
Contributor

Thanks for this! When you say it "can be loaded again" does this mean the problem occurs frequently? I'd like to reproduce it myself before I make the change, and I can't seem to.

@EricByers
Copy link
Author

@malectro Sorry I forgot to include the actual pertinent information. We were not actually seeing the doubled up requests happening in normal usage using the image. One of the mixpanel events happens inside of a onbeforeunload or an unonload, and in Chrome and for whatever reason those seem to trigger double.

I found this which somewhat describes the same problem. Small image, non-cached, etc
http://stackoverflow.com/questions/14504313/dynamic-generated-image-is-requested-twice-when-using-jquery-lazy-loading-in-goo

I also think I have a jsfiddle that shows the problems, if you watch the network tab in chrome, or via a proxy you'll see the request double up (there is a third request there as well, but I believe that is jsfiddle's own tracking 😄 )
http://jsfiddle.net/975LW/1/

@malectro
Copy link
Contributor

Wonderful. I made the change in the mixpanel src for the fiddle and it fixed the issue. We'll definitely include it in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants